package com.xy.biz.base.controller;

import com.xy.biz.base.client.UnitConvertClient;
import com.xy.biz.base.domain.req.GetUnitConvertRequest;
import com.xy.biz.base.domain.resp.GetUnitConvertResponse;
import com.xy.biz.base.service.UnitConvertService;
import com.xy.lang.domain.Result;
import com.xy.lang.validation.annotation.Validatable;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "单位换算服务")
@Slf4j
@RestController
@RequestMapping("/api/base/unit_convert")
public class UnitConvertController implements UnitConvertClient {

    @Autowired
    private UnitConvertService unitConvertService;

    @Validatable
    @Override
    public Result<GetUnitConvertResponse> getMultiplier(@RequestBody GetUnitConvertRequest request) {
        GetUnitConvertResponse response = unitConvertService.getMultiplier(request);
        if(response == null) {
            return Result.ofNotFound();
        }
        return Result.success(response);
    }
}
